import mockApi from "@/api/mockApi";
import type {FacilityMaintenanceRecordForm} from '@/types/req/facilityMaintenanceRecordForm'
import type {FacilityMaintenanceRecordQueryForm} from '@/types/req/facilityMaintenanceRecordQueryForm'
import type {FacilityMaintenanceRecord} from '@/types/resp/facilityMaintenanceRecord'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";
import dayjs from "dayjs";

export default class facilityMaintenanceRecordApi {
  static facilityMaintenanceRecords: FacilityMaintenanceRecord[] = [
    {id: 1, facilityId: 1, facilityName: '充电应急灯', maintenanceStartDate: dayjs('2024-02-02 08:30:00'), maintenanceEndDate: dayjs('2024-02-02 18:00:00'), staffId: 1, staffName: '赵六', remark: '一切正常', createTime: '2024-01-01 12:12:12'},
    {id: 2, facilityId: 2, facilityName: '高空摄像头', maintenanceStartDate: dayjs('2024-03-03 08:30:00'), maintenanceEndDate: dayjs('2024-03-03 18:00:00'), staffId: 2, staffName: '张三', remark: '一切正常', createTime: '2024-02-02 12:12:12'},
    {id: 3, facilityId: 3, facilityName: '顶楼换气扇', maintenanceStartDate: dayjs('2024-04-04 08:30:00'), maintenanceEndDate: dayjs('2024-04-04 18:00:00'), staffId: 3, staffName: '李四', remark: '一切正常', createTime: '2024-03-03 12:12:12'},
    {id: 4, facilityId: 4, facilityName: '大厅电风扇', maintenanceStartDate: dayjs('2024-05-05 08:30:00'), maintenanceEndDate: dayjs('2024-05-05 18:00:00'), staffId: 4, staffName: '王五', remark: '一切正常', createTime: '2024-04-04 12:12:12'}
  ]

  static async save (facilityMaintenanceRecordForm: FacilityMaintenanceRecordForm): Promise<Result<void>> {
    console.log('facilityMaintenanceRecordApi save params', facilityMaintenanceRecordForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (facilityMaintenanceRecordQueryForm: FacilityMaintenanceRecordQueryForm): Promise<Result<Page<FacilityMaintenanceRecord>>> {
    console.log('facilityMaintenanceRecordApi find params', facilityMaintenanceRecordQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(facilityMaintenanceRecordApi.facilityMaintenanceRecords)
    return response.data
  }

  static async findById (id: number): Promise<Result<FacilityMaintenanceRecord>> {
    console.log('facilityMaintenanceRecordApi findById id', id)
    let target = {}
    for (const a of facilityMaintenanceRecordApi.facilityMaintenanceRecords) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<FacilityMaintenanceRecord> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('facilityMaintenanceRecordApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
